package com.xz.disk.utils;


import lombok.Data;

/**
 * @program: Official
 * @description: 返回结果
 * @author: Shawn
 * @create: 2019-11-13 10:21
 **/
@Data
public class PageResult {
    private Integer code;
    private String msg;
    private Object data;
    private Integer pageIndex; // 当前页
    private Integer pageSize; // 每页数量
    private Integer pageCount; // 总页数
    private Integer rowCount;  // 总行数

    public static PageResult MESSAGE(ResCode code, String msg){
        return new PageResult(code.getIndex(),msg,null);
    }
    public static PageResult SUCCESS(){
        return new PageResult(ResCode.SUCCESS.getIndex(),"",null);
    }
    public static PageResult SUCCESS(String msg){
        return new PageResult(ResCode.SUCCESS.getIndex(),msg,null);
    }
    public static PageResult SUCCESS(Object data){
        return new PageResult(ResCode.SUCCESS.getIndex(),"",data);
    }
    public static PageResult SUCCESS(String msg, Object data){
        return new PageResult(ResCode.SUCCESS.getIndex(),msg,data);
    }

    public static PageResult SUCCESS(Object data, Page param){
        return new PageResult(ResCode.SUCCESS.getIndex(),"",data,param.getPageIndex(),param.getPageSize(),param.getPageCount(),param.getRowCount());
    }
    public static PageResult SUCCESS(String msg,Object data, Page param){
        return new PageResult(ResCode.SUCCESS.getIndex(),msg,data,param.getPageIndex(),param.getPageSize(),param.getPageCount(),param.getRowCount());
    }

    public static PageResult FAIL(){
        return new PageResult(ResCode.ERROR.getIndex(),"",null);
    }
    public static PageResult FAIL(String msg){
        return new PageResult(ResCode.ERROR.getIndex(),msg,null);
    }
    public static PageResult ERROR(String msg){
        return new PageResult(ResCode.ERROR.getIndex(),msg,null);
    }
    private PageResult(){}
    public PageResult(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public PageResult(Integer code, String msg, Object data, Integer pageIndex, Integer pageSize, Integer pageCount, Integer rowCount) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.pageCount = pageCount;
        this.rowCount = rowCount;
    }
}
